<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="user"></Secondnav>
    </div>

    <!-- 主体内容 -->
   <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>商城栏目门店/商品/分类列表</legend>
            </fieldset>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
            <div class="buttop">
              <button type="button" class="layui-btn layui-btn-normal" @click="addData">关联门店/商品/分类</button>
            </div>
            <Tables
              :fdate="pdate"
              :result="res"
              height="430"
              :totalCount="totalRows"
              :pageNumber="curindex"
              :fbtn="btn"
            ></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../../common/pagetop.vue";
import Secondnav from "../../common/secondnav.vue";
import Tables from "../../common/tables.vue";
import Search from "../../common/search.vue";
export default {
  name: "storeadv",
  components: { Pagetop, Secondnav, Tables, Search },
  data() {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      cid:this.$route.query.id,
      layoutid:this.$route.query.layoutid,
      targetType:this.$route.query.targetType
    };
  },
  mounted() {
      this.getdate();
      this.getsearch();
    //   alert(JSON.stringify(this.$route.query.targetType))
  },
  methods: {
      getdate: function () {
      var _this = this;
      var url = "/advert/bapi/v1.9/advert";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          sort:'createAt,DESC',
          'categoryId.equals': _this.cid,
          
          'status.equals':'ENABLE'
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          dates[res[i].key + ".equals"] = res[i].val;
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          sort:'createAt,DESC',
          'categoryId.equals': _this.cid,
          //'status.equals':'ENABLE'
        };
      }
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        var arr = [];
        if(_this.targetType == 5||_this.layoutid==3){
          arr[0] = [
          { field: "id", title: "ID" },
          { field: "title", title: "广告标题"},
          {
            field: "appointed",
            title: "商城类型",
            templet: function (d) {
              if( d.appointed == 1) return '现金商城';
              else if( d.appointed == 2) return 'UC商城';
              else return 'WUC商城'
            },
          },
          { field: "appointedName", title: "商品名称" },
            {
              field: "appointedLogo",
              title: "商品图片",
              templet:
                '<div><img src="{{d.appointedLogo}}" style="display: inline-block; height: 100%;"></div>',
            },
          { field: "rank", title: "排序"},
          {
            field: "picUrl",
            title: "广告图",
            templet:
              '<div><img src="{{d.picUrl}}" style="display: inline-block; height: 100%;"></div>'
          },
           { field: "createAt", title: "创建时间",templet:function (d) {
            return FormatDate(d.createAt, 3);
            } },
          {
            field: "right",
            title: "操作",
            width: "120",
            fixed: "right",
            templet: function (d) {
              var str =''
                //'<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
                 var str1 =
                '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
              return str  + str1 ;
            },
          },
        ];
        }else{
          arr[0] = [
          { field: "id", title: "ID" },
          { field: "title", title: "广告标题"},
          {
            field: "targetType",
            title: "广告类型",
            templet: function (d) {
              return '商品分组'
            },
          },
          { field: "rank", title: "排序"},
          {
            field: "picUrl",
            title: "广告图",
            templet:
              '<div><img src="{{d.picUrl}}" style="display: inline-block; height: 100%;"></div>'
          },
           { field: "createAt", title: "创建时间",templet:function (d) {
            return FormatDate(d.createAt, 3);
            } },
          {
            field: "right",
            title: "操作",
            width: "120",
            fixed: "right",
            templet: function (d) {
              var str =''
                //'<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
                 var str1 =
                '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
              return str  + str1 ;
            },
          },
        ];
        }
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page + 1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "title", title: "广告标题", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
    //   alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    addData: function (data) {
      var _this = this;
      layer.open({
        type: 2,
        title: "新增商城广告信息",
        content: baseurl + "/storeadvadd",
        area: _this.screens() < 2 ? ["90%", "90%"] : ["900px", "900px"],
        success: function (layero, index) {
          var ifremeWin = window[layero.find("iframe")[0]["name"]];
          var dates={
          	cid:_this.cid
          }
          ifremeWin.getdates(dates);
        }
      });
    },
    editInfo: function (data) {
      var _this = this;
      if(this.$route.query.targetType == 5){
          layer.open({
        type: 2,
        title: "编辑商城广告信息",
        content: baseurl + "/storeadvshop",
        area: _this.screens() < 2 ? ["90%", "90%"] : ["900px", "900px"],
        success: function (layero, index) {
          var ifremeWin = window[layero.find("iframe")[0]["name"]];
          data.cid=_this.cid
          ifremeWin.getdates(data);
        }
      });
      }else{
        layer.open({
        type: 2,
        title: "编辑商城广告信息",
        content: baseurl + "/storeadvadd",
        area: _this.screens() < 2 ? ["90%", "90%"] : ["900px", "900px"],
        success: function (layero, index) {
          var ifremeWin = window[layero.find("iframe")[0]["name"]];
          data.cid=_this.cid
          ifremeWin.getdates(data);
        }
      });
      }
     
    },
    delInfo: function (data) {
      var _this = this;
      layer.confirm("是否确认删除？", function () {
        var url = "/advert/bapi/v1.9/advert/" + data.id;
        ajaxRequest(url, "DELETE", "json", "", function (ret, err) {
          layer.msg("操作成功");
          setTimeout(function () {
            _this.getdate();
          }, 1000);
        });
      });
    },
    screens: function () {
      return screen();
    },
  },
   
  updated: function () {
    var _this = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  },
};
</script>
<style>
</style>